package org.flowable.pz.serialize;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.flowable.pz.entity.dto.FlowableProcessDto;
import org.flowable.pz.enums.FlowableStatusEnum;

import java.io.IOException;

/**
 * 序列化状态名
 * */
public class FlowableInstanceStatusDescriptionSerialize extends JsonSerializer<String> {
    @Override
    public void serialize(String s, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException {
        FlowableProcessDto currentValue = (FlowableProcessDto)gen.getCurrentValue();

        if(currentValue.getStatus() == null){
            gen.writeNull();
        }else {
            gen.writeString(FlowableStatusEnum.getByCode(currentValue.getStatus()).getDescription());
        }
    }
}
